package com.aaa.web.service.impl.studentserviceimpl;

import com.aaa.entity.AppStcardApprove;
import com.aaa.entity.BackSchool;
import com.aaa.entity.Employee;
import com.aaa.phone.systemconst.ISystemConst;
import com.aaa.util.EmpUtil;
import com.aaa.web.commons.Query;
import com.aaa.web.commons.Result;
import com.aaa.web.dao.studentapprovedao.StudentApproveDao;
import com.aaa.web.service.studentapproveservice.IStudentApproveService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @description:学生后台管理业务实现层
 * @author: 王林林
 * @create: 2018/12/28 9:29
 **/
@Service
public class StudentApproveServiceImpl implements IStudentApproveService {
    @Autowired
    private StudentApproveDao dao;
    /**获取所有学生用户信息*/
    @Override
    public Map getAllStudentUser(Query query,AppStcardApprove stcardApprove) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<Object, Object> map = new HashMap<>();
        List<Map> list = dao.getAllStudentUser(stcardApprove);
        map.put("data",list);
        map.put("count",dao.getAllStudentUserCount(stcardApprove));
        map.put("code", ISystemConst.ZERO);
        map.put("msg","");
        return map;
    }
    /**根据手机号更改通过认证的学生用户信息*/
    @Transactional
    @Override
    public Result studentapprovePass(String telephone) {
        int i=dao.updateUserInfoForStudent(telephone);
        AppStcardApprove appStcardApprove=new AppStcardApprove();
        Integer employeeid = EmpUtil.getEmp().getEmployeeid();
        appStcardApprove.setEmployeeid(employeeid);
        appStcardApprove.setTelephone(telephone);
        int a=dao.updateStudentApprove(appStcardApprove);
        Result result = new Result();
        if(i>ISystemConst.ZERO){
            result.setCode(i);
        }else{
            result.setCode(i);
        }
        return result;
    }
    /**根据手机号取消认证的学生用户信息*/
    @Override
    public Result delStudentApprove(String telephone) {
        int i = dao.delUserInfoForStudent(telephone);
        int a=dao.delStApprove(telephone);
        Result result = new Result();
        if(i>ISystemConst.ZERO){
            result.setCode(i);
        }else{
            result.setCode(i);
        }
        return result;
    }
    /**获取所有需要认证的信息*/
    @Override
    public Map getAllStudentApprove(Query query,AppStcardApprove stcardApprove) {
        int page = query.getPage();
        int size = query.getLimit();
        PageHelper.startPage(page,size);
        Map<Object, Object> map = new HashMap<>();
        List<Map> list = dao.getAllStudentApprove(stcardApprove);
        map.put("data",list);
        map.put("count",dao.getAllStudentApproveCount(stcardApprove));
        map.put("code",ISystemConst.ZERO);
        map.put("msg","");
        return map;
    }
    /**select框根据数据库动态展示数据*/
    @Override
    public List<BackSchool> getSchoolName() {
        return dao.getSchoolName();
    }
}
